package com.zh.work.service.platform.channel.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zh.work.dao.platform.channel.ChannelLogMapper;
import com.zh.work.entity.channel.ChannelLogEntity;
import com.zh.work.entity.merch.MerchInfoEntity;
import com.zh.work.service.platform.channel.ChannelLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @Description: 渠道业务日志实现
 * @Author: Liard
 * @Create in: 2020/10/15 11:28
 * @Version: 1.0.1
 */
@Service
public class ChannelLogServiceImpl extends ServiceImpl<ChannelLogMapper, ChannelLogEntity> implements ChannelLogService {

    @Autowired
    private ChannelLogMapper dao;

    @Override
    public IPage<ChannelLogEntity> selectChannelLogPage(Page<ChannelLogEntity> page, ChannelLogEntity param) {
        MerchInfoEntity mrc = dao.getMrcInfo(param.getOrderno());
        if (Objects.nonNull(mrc)) { param.setOrderno(mrc.getMerchNo()); }
        return dao.selectPage(page, new LambdaQueryWrapper<ChannelLogEntity>().like(
                StrUtil.isNotEmpty(param.getOrderno()), ChannelLogEntity::getOrderno, param.getOrderno()
        ).orderBy(true, false, ChannelLogEntity::getAddDate));
    }

    @Override
    public List<ChannelLogEntity> selectChannelLogDownLoad(ChannelLogEntity param) {
        MerchInfoEntity mrc = dao.getMrcInfo(param.getOrderno());
        if (Objects.nonNull(mrc)) { param.setOrderno(mrc.getMerchNo()); }
        List<ChannelLogEntity>  data =   dao.selectList(new LambdaQueryWrapper<ChannelLogEntity>().like(
                StrUtil.isNotEmpty(param.getOrderno()), ChannelLogEntity::getOrderno, param.getOrderno()
        ).orderBy(true, false, ChannelLogEntity::getAddDate));
        return  data;

    }
}
